package com.hsl.housaileibot001.controller;

import com.hsl.housaileibot001.common.PageRequest;
import com.hsl.housaileibot001.common.PageResult;
import com.hsl.housaileibot001.common.Result;
import com.hsl.housaileibot001.model.vo.WrongQuestionVO;
import com.hsl.housaileibot001.service.WrongQuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 错题本控制器
 */
@Tag(name = "错题本接口", description = "错题本相关接口")
@RestController
@RequestMapping("/practice")
public class WrongQuestionController {

    @Resource
    private WrongQuestionService wrongQuestionService;

    @Operation(summary = "获取错题列表", description = "分页获取当前用户的错题列表")
    @GetMapping("/wrong-questions")
    public Result<PageResult<WrongQuestionVO>> getWrongQuestions(@ModelAttribute PageRequest pageRequest) {
        try {
            PageResult<WrongQuestionVO> result = wrongQuestionService.getWrongQuestions(pageRequest);
            return Result.success(result);
        } catch (Exception e) {
            return Result.error("获取错题列表失败：" + e.getMessage());
        }
    }

    @Operation(summary = "删除错题", description = "删除指定的错题")
    @DeleteMapping("/wrong-questions/{id}")
    public Result<Void> deleteWrongQuestion(
            @Parameter(description = "错题ID") @PathVariable Long id) {
        try {
            wrongQuestionService.deleteWrongQuestion(id);
            return Result.success();
        } catch (Exception e) {
            return Result.error("删除错题失败：" + e.getMessage());
        }
    }

    @Operation(summary = "获取错题统计信息", description = "获取当前用户的错题统计信息")
    @GetMapping("/wrong-questions/stats")
    public Result<Map<String, Object>> getStats() {
        try {
            Map<String, Object> stats = wrongQuestionService.getStats();
            return Result.success(stats);
        } catch (Exception e) {
            return Result.error("获取统计信息失败：" + e.getMessage());
        }
    }
}

